package com.putprize.semantic;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.Logger;
//import org.apache.log4j.PropertyConfigurator;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParameterException;

public class SemanticTaggerApp {
	
	private static final Logger _log = Logger.getLogger(SemanticTaggerApp.class);
	
	@Parameter(description="Mode", names="-mode")
	private String mode = "server";
	
	@Parameter(description="Prop", names="-prop")
	private String location = "SemanticTagger.properties";	
	
	private static Properties prop = new Properties();
	
	public static void main(String[] args) {
		
		//PropertyConfigurator.configure("log4j.properties");
		
		SemanticTaggerApp app = new SemanticTaggerApp();
		
		JCommander com = new JCommander(app);
		
		try {
			com.parse(args);
		} catch (ParameterException e){
			System.err.println(e.getMessage());
			com.usage();
			return;
		}
		
    	File file = new File(app.location);
    	if (file.exists()) {
    		try {
    			_log.info("Init Prop "+app.location);
				prop.load(new FileInputStream(file));
				_log.info("Done");
			} catch (FileNotFoundException e) {
				e.printStackTrace();
				_log.fatal(e);
			} catch (IOException e) {
				e.printStackTrace();
				_log.fatal(e);
			}
    	}
    	
    	if (app.mode.equals("server"))
    		SemanticTaggerServer.run(prop);
        if (app.mode.equals("thrift"))
            SemanticTaggerServer.runThriftServer(prop);
	}

}
